package org.shj.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;


public class FileUtils {

	public static void readFile(String filePath) throws IOException{
		File file = new File(filePath);
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
		String line;
		while((line = br.readLine()) != null){
			System.out.println(line);
		}
		br.close();
	}
	
	public static void append2File(String filePath, String content) throws IOException{
		RandomAccessFile raf = new RandomAccessFile(filePath, "rw");
		raf.seek(raf.length());
		raf.writeBytes(content);
		raf.close();
	}
	
	public static void main(String[] args) throws Exception {
		String filePath = "F:\\download\\test.log";
		FileUtils.append2File(filePath, "aaa");
		FileUtils.readFile(filePath);
	}
}
